///////////////////////////////////////////////////////////////////////////////
// Util vs1
// dependencies: none;
// Copyright 2006, NetX. All rights Reserved.
///////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////
// Windows class:
//////////////////////////////////////////////////////////////////////

function Windows_getWindow(name) {
	var p = this.popups[name];
	if(!p) {
		p = new Popup(name, false);
		this.popups[name] = p;
	}
	else {
		p.isNew = false;
	}
	return p;
}

function Windows_getPopup(name) {
	var p = this.popups[name];
	if(!p) {
		p = new Popup(name, true);
		this.popups[name] = p;
	}
	else {
		p.isNew = false;
	}
	return p;
}

function Windows_class() {
	this.popups = new Object();
	// Methods:
	this.getWindow = Windows_getWindow;
	this.getPopup = Windows_getPopup;
};

var Windows = new Windows_class();


//////////////////////////////////////////////////////////////////////
// Popup class:
//////////////////////////////////////////////////////////////////////

function Popup(name, popup) {
	this._name = name;
	this.x = false;
	this.y = false;
	this.width = false;
	this.height = false;
	this.isNew = true;
	this.window = false;
	if(popup) {
		this.scrollbars = false;
		this.menubar = false;
		this.resizable = false;
	}
	else {
		this.scrollbars = true;
		this.menubar = true;
		this.resizable = true;
	}
	// Methods:
	this.setSize = Popup_setSize;
	this.setBounds = Popup_setBounds;
	this.setScrollbars = Popup_setScrollbars;
	this.setMenubar = Popup_setMenubar;
	this.setResizable = Popup_setResizable;
	this.open = Popup_open;
}

function Popup_setSize(width, height) {
	this.width = width;
	this.height = height;
	return this;
}

function Popup_setBounds(x, y, width, height) {
	this.x = x;
	this.y = y;
	this.setSize(width, height);
	return this;
}

function Popup_setScrollbars(value) {
	this.scrollbars = value;
	return this;
}

function Popup_setMenubar(value) {
	this.menubar = value;
	return this;
}

function Popup_setResizable(value) {
	this.resizable = value;
	return this;
}

function Popup_open(link) {
	if(this.window) {
		if(!this.window.closed) {
			this.window.close();
		}
	}
	var options = "";
	options = (options=="" ? options : options+", ") + (this.x ? "screenX="+this.x+", screenY="+this.y+", left="+this.x+", top="+this.y : "");
	options = (options=="" ? options : options+", ") + (this.width ? "width="+this.width+", height="+this.height : "");
	options = (options=="" ? options : options+", ") + "scrollbars="+(this.scrollbars ? "yes" : "no");
	options = (options=="" ? options : options+", ") + "menubar="+(this.menubar ? "yes" : "no");
	options = (options=="" ? options : options+", ") + "resizable="+(this.resizable ? "yes" : "no");
	this.window = window.open(link, this._name, options);
	this.window.focus();
}




